import request from '@/utils/request'

// -------------------------登录注册-----------------------
const register = (data) => {
  return request({
    url: '/users/register',
    method: 'post',
    data,
  })
}

const exist = (username) => {
  return request({
    url: `/users/exist?username=${username}`,
    method: 'get',
  })
}

const login = (data) => {
  return request({
    url: '/users/login',
    method: 'post',
    data,
  })
}

// -------------------------查询用户-----------------------
const pageByCond = (currentPage, pageSize, data) => {
  return request({
    url: `/users/list?pageNum=${currentPage}&pageSize=${pageSize}`,
    method: 'post',
    data,
  })
}

const getById = (id) => {
  return request({
    url: `/users/details/${id}`,
    method: 'get',
  })
}

const getByUsername = (username) => {
  return request({
    url: `/users/details?username=${username}`,
    method: 'get',
  })
}

const get = (data) => {
  return request({
    url: `/users/get`,
    method: 'post',
    data,
  })
}

const remove = (id) => {
  return request({
    url: `/users/remove/${id}`,
    method: 'delete',
  })
}

// -------------------------修改用户-----------------------
const updateById = (data) => {
  return request({
    url: `/users/update`,
    method: 'put',
    data,
  })
}

export default {
  register,
  exist,
  login,
  getById,
  getByUsername,
  updateById,
  remove,
  pageByCond,
}
